/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ejb.settings;

import java.io.Serializable;
import java.util.List;
import javax.ejb.EJBException;
import javax.ejb.Singleton;
import jpa.controller.ConstantesJpaController;
import jpa.entities.Constantes;

/**
 *
 * @author Diego Curbelo
 */
@Singleton
public class ConstantesEJB implements Serializable{

    public ConstantesEJB() {
    }
    
public List<Constantes> listarConstantes()throws EJBException{
return new ConstantesJpaController().findConstantesEntities();
}

public Constantes devolverConstantes()throws EJBException{
List<Constantes>constantes;
Constantes constante;
constantes =listarConstantes();
if(constantes!=null && !constantes.isEmpty()){
constante = constantes.get(0);
}else{
constante = new Constantes(1, 0, 0, 0, 0, 0, 0, 0);
}
return constante;
}

public boolean modificarConstantes(Constantes constante)throws EJBException{
try{
    List<Constantes>constantes;
    constantes =listarConstantes();
    if(constantes!=null  && !constantes.isEmpty()){
    new ConstantesJpaController().edit(constante);
    }else{
    new ConstantesJpaController().create(constante);
    }
    return true;
}catch(Exception e){
    e.getMessage();
    return false;
}

}

}
